//
//  LeftCateView.m
//  gungunchou
//
//  Created by lyzbmacos3 on 2019/1/10.
//  Copyright © 2019年 xskj. All rights reserved.
//

#import "LeftCateView.h"
#import "CateHeadCell.h"
#import "CateContentCell.h"

@interface LeftCateView () <UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *table;
@property (nonatomic, copy) NSArray *contentImgs;
@property (nonatomic, copy) NSArray *contentNames;
@property (weak, nonatomic) IBOutlet UIView *maskView;
@end

@implementation LeftCateView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self = [[NSBundle mainBundle] loadNibNamed:@"LeftCateView" owner:nil options:nil].firstObject;
        [self configs];
    }
    return self;
}

- (void)configs
{
    self.table.delegate = self;
    self.table.dataSource = self;
    [self.table registerNib:[UINib nibWithNibName:@"CateHeadCell" bundle:nil] forCellReuseIdentifier:@"CateHeadCell"];
    [self.table registerNib:[UINib nibWithNibName:@"CateContentCell" bundle:nil] forCellReuseIdentifier:@"CateContentCell"];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(maskTap)];
    self.maskView.userInteractionEnabled = YES;
    [self.maskView addGestureRecognizer:tap];
}

- (void)awakeFromNib
{
    [super awakeFromNib];
}

- (void)maskTap
{
    self.hidden = YES;
}

- (NSArray *)contentImgs
{
    return @[@"homeSelect",@"home_left_order",@"home_left_integral",@"home_left_address",@"home_left_center",@"home_left_jiang",@"home_left_intro"];
}

- (NSArray *)contentNames
{
    return @[@"主页",@"我的订单",@"积分",@"收货地址",@"个人中心",@"积分抽奖",@"公司介绍"];
}

#pragma mark - delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 8;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *theCell;
    NSInteger row = indexPath.row;
    if (row == 0) {
        CateHeadCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CateHeadCell"];
        
        theCell = cell;
    }
    else {
        CateContentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CateContentCell"];
        NSString *imgStr = self.contentImgs[indexPath.row-1];
        UIImage *img = [UIImage imageNamed:imgStr];
        NSString *name = self.contentNames[indexPath.row-1];
        cell.imgV.image = img;
        cell.nameLbl.text = name;
        theCell = cell;
    }
    return theCell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.clickBlock) {
        self.clickBlock(indexPath.row);
    }
}
@end
